home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0429.dms / q0429.adf / libray / liblight / jittered.c < prev    next >
C/C++ Source or Header  |  1991-08-08  |  2KB  |  88 lines

  1. /*
  2.  * jittered.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: jittered.c,v 4.0 91/07/17 14:34:43 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    jittered.c,v $
  19.  * Revision 4.0  91/07/17  14:34:43  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "light.h"
  24. #include "jittered.h"
  25.  
  26. static LightMethods *iJitteredMethods = NULL;
  27.  
  28. Jittered *
  29. JitteredCreate(pos, e1, e2)
  30. Vector *pos, *e1, *e2;
  31. {
  32.     Jittered *j;
  33.  
  34.     j = (Jittered *)share_malloc(sizeof(Jittered));
  35.  
  36.     j->pos = *pos;
  37.     j->e1 = *e1;
  38.     j->e2 = *e2;
  39.  
  40.     return j;
  41. }
  42.  
  43. LightMethods *
  44. JitteredMethods()
  45. {
  46.     if (iJitteredMethods == (LightMethods *)NULL) {
  47.         iJitteredMethods = LightMethodsCreate();
  48.         iJitteredMethods->intens = JitteredIntens;
  49.         iJitteredMethods->dir = JitteredDirection;
  50.     }
  51.     return iJitteredMethods;
  52. }
  53.  
  54. int
  55. JitteredIntens(jit, lcolor, cache, ray, dist, noshadow, color)
  56. Jittered *jit;
  57. Color *lcolor, *color;
  58. ShadowCache *cache;
  59. Ray *ray;
  60. Float dist;
  61. int noshadow;
  62. {
  63.     return !Shadowed(color, lcolor, cache, ray, dist, noshadow);
  64. }
  65.  
  66. void
  67. JitteredDirection(lp, pos, dir, dist)
  68. Jittered *lp;
  69. Vector *pos, *dir;
  70. Float *dist;
  71. {
  72.     /*
  73.      * Choose a location with the area define by corner, e1
  74.      * and e2 at which this sample will be taken.
  75.      */
  76.     VecAddScaled(lp->pos, nrand(), lp->e1, &lp->curpos);
  77.     VecAddScaled(lp->curpos, nrand(), lp->e2, &lp->curpos);
  78.     VecSub(lp->curpos, *pos, dir);
  79.     *dist = VecNormalize(dir);
  80. }
  81.  
  82. JitteredMethodRegister(meth)
  83. UserMethodType meth;
  84. {
  85.     if (iJitteredMethods)
  86.         iJitteredMethods->user = meth;
  87. }
  88.